<?php

namespace app\admin\controller;

use app\base\model\system\{SystemMenus, SystemRole};
use app\admin\service\HomeService;

class AdminHomeController extends adminAuthController
{

    public function getAdminInfo()
    {
        //获取当前登录后台的管理员信息
        $adminInfo = $this->adminInfo;
        //需要根据不同的角色给出不同的信息
        $roles = explode(',', $adminInfo['role_ids']);
        $data = [
            'admin_name' => $adminInfo['admin_name'],
            'real_name' => $adminInfo['real_name'],
            'head_photo' => $adminInfo['head_photo'],
            'menuList' => SystemMenus::menuList(),
            'role_name' => SystemRole::where('role_id', $roles[0])->field('role_name')->find()
        ];
        return $this->successReturn($data);
    }

    public function getHomeData()
    {

        $today_start = date('Y-m-d 00:00:00');
        $today_end = date('Y-m-d 23:59:59');

        $data = [
            'statistics_info' => [
                'history_user_total' => HomeService::instance()->getUserNum(),
                'today_user_total' => HomeService::instance()->getUserNum(['register_time' => ['BETWEEN', [$today_start, $today_end]]]),
                'history_pay_money' => HomeService::instance()->getPayMoney(),
                'today_pay_money' => HomeService::instance()->getPayMoney(['create_time' => ['BETWEEN', [$today_start, $today_end]]]),
                'history_initiate_wish_num' => HomeService::instance()->getInitiateNum(),
                'today_initiate_wish_num' => HomeService::instance()->getInitiateNum(['create_time' => ['BETWEEN', [$today_start, $today_end]]]),
                'history_initiate_user_num' => HomeService::instance()->getInitiateUserNum(),
                'today_initiate_user_num' => HomeService::instance()->getInitiateUserNum(['create_time' => ['BETWEEN', [$today_start, $today_end]]]),
                'history_group_success_num' => HomeService::instance()->getGroupSuccessNum(),
                'today_group_success_num' => HomeService::instance()->getGroupSuccessNum(['create_time' => ['BETWEEN', [$today_start, $today_end]]]),
                'history_group_success_user_num' => HomeService::instance()->getGroupSuccessUserNum(),
                'today_group_success_user_num' => HomeService::instance()->getGroupSuccessUserNum(['create_time' => ['BETWEEN', [$today_start, $today_end]]]),
            ]
        ];

        return $this->successReturn($data);
    }
}


